package com.xml.demo.mapper;

import com.xml.demo.model.User;
import org.apache.ibatis.annotations.*;

import java.util.Map;

/**
 * @ClassName UserMapper
 * @description: TODO
 * @author: 朱同学
 * @Date 2021/5/16 15:22
 **/
@Mapper
public interface UserMapper {

    @Insert("insert into USER(id, user_name) VALUES(#{id}, #{name})")
    void save(String name, Integer id);

    @Select("select id,user_name userName from user where id = #{id}")
    User findById(Integer id);

    @Delete("DELETE FROM user WHERE id =#{id}")
    void delete(Integer id);

    @Insert("insert into USER(id, user_name) VALUES(#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR})")
    void saveMap(Map<String, Object> map);

    @Insert("insert into USER(id, user_name) VALUES(#{id}, #{userName})")
    void saveUser(User user);

    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "userName", column = "user_name")
    })
    @Select("select id,user_name from user where user_name = #{name}")
    User findByName(String name);
}
